/*
 * @Description: 可视化分析接口
 * @Author: chenju
 * @Date: 2022-04-06 15:38:04
 * @LastEditors: chenju
 * @LastEditTime: 2023-01-19 10:57:20
 */
import { get, getBlob } from '@/utils/http';
import {
  GetOrgListResult,
  GetHierarchyListParams,
  GetHierarchyListResult,
  OrgExportParams,
  OrgDetailExportParams,
  GetScopeListResult,
  ScopeScopeExportParams,
  ScopeClassExportParams,
  ScopeSourceExportParams,
  GetPeriodListParams,
  GetPeriodListResult,
  GetMonthPeriodListParams,
  GetMonthPeriodListResult,
  PeriodExportParams,
  PeriodIntensityExportParams,
  queryAnalysisParams,
  queryAnalysisYearParams,
  queryOrgAnalysisParams,
  queryAnalysisRes,
  queryOrgAnalysisPieRes,
  queryOrgAnalysisSankeyRes,
  analysisTopType
} from './model/visualAnalysisModel';

enum Api {
  // 按组织分布
  GET_ORG_LIST = '/inventory/visibleAnalysis/listByOrg',
  // 按组织分布-单个组织排放详情
  GET_ORG_SIGLE_DETAIL = '/inventory/dataStatistical/hierarchyList',
  // 按组织分布-饼图-导出excel
  GET_ORG_EXPORT = '/inventory/visibleAnalysis/exportListByOrg',
  // 按组织分布-单个组织排放详情-导出excel
  GET_ORG_DETAIL_EXPORT = '/inventory/visibleAnalysis/exportByOrg',

  // 按范围分布
  GET_DATA_BY_SCOPE = '/inventory/visibleAnalysis/dataByScope',
  // 按范围分布-导出范围分布
  GET_DATA_BY_SCOPE_EXPORT = '/inventory/visibleAnalysis/exportScopeByScope',
  // 按范围分布-导出范围类别分布
  GET_DATA_BY_CLASS_EXPORT = '/inventory/visibleAnalysis/exportCategoryByScope',
  // 按范围分布-导出温室气体类型分布excel
  GET_DATA_BY_SOURCE_EXPORT = '/inventory/visibleAnalysis/exportSourceByScope',

  // 按时间分布-碳排放数据对比
  GET_DATA_PERIOD = '/inventory/visibleAnalysis/listByPeriod',
  // 按时间分布-月度碳排放趋势
  GET_DATA_PERIOD_MONTH = '/inventory/visibleAnalysis/listMonthByPeriod',
  // 按按时间分布-导出碳排放数据对比
  GET_DATA_PERIOD_EXPORT = '/inventory/visibleAnalysis/exportByPeriod',
  // 按时间分布-月度碳排放趋势-导出排放强度excel
  GET_DATA_PERIOD_INTENSITY_EXPORT = '/inventory/visibleAnalysis/exportEmissionByPeriod',

  // 盘查-图形化趋势
  // 近12月碳排放及强度趋势分析 - 王佩宇
  GET_MONTH_QUERYANALYSIS = '/inventory/trend/queryAnalysis',
  // 按年碳排放及强度趋势分析 - 王佩宇
  GET_YEAR_QUERYANALYSIS = '/inventory/trend/queryAnalysisYear',
  // 盘查-碳排放分布分析-饼图
  GET_PIE_QUERYORGANALYSIS = '/inventory/trend/queryOrgAnalysis',
  // 盘查-碳排放分布分析-按排放源-柱图
  GET_BAR_QUERYORGBYGHGSOURCEANALYSIS = '/inventory/trend/queryOrgByMaterialNameAnalysis',
  // 盘查-碳排放分布分析-按排放源-桑基图
  GET_SANKEY_QUERYORGBYMATERIALITEMANALYSIS = '/inventory/trend/queryOrgByMaterialItemAnalysis',
  // 下载各标准的报表
  GET_STATISTICSREPORT_EXPORT = '/inventory/statisticsReport/downloadReport',
  // 盘查-图形趋势分析-标头
  GET_ANALYSIS_HEADER = '/inventory/trend/queryAnalysisTop',
  // 可视化查询任务信息
  TREND_QUERY_TASK = '/inventory/trend/queryTask'
}

// 按组织分布
export const getOrgList = (taskNo: string): Promise<GetOrgListResult[]> =>
  get(Api.GET_ORG_LIST, { taskNo });

// 按组织分布-单个组织排放详情
export const getHierarchyList = (
  params: GetHierarchyListParams
): Promise<GetHierarchyListResult[]> => get(Api.GET_ORG_SIGLE_DETAIL, params);

// 按组织分布-饼图-导出excel
export const orgExport = (params: OrgExportParams) => getBlob(Api.GET_ORG_EXPORT, params);

// 按组织分布-单个组织排放详情-导出excel
export const orgDetailExport = (params: OrgDetailExportParams) =>
  getBlob(Api.GET_ORG_DETAIL_EXPORT, params);

// 按范围分布
export const getHierarchyScopeList = (taskNo: string): Promise<GetScopeListResult[]> =>
  get(Api.GET_DATA_BY_SCOPE, { taskNo });

// 按范围分布-按范围导出excel
export const scopeScopeExport = (params: ScopeScopeExportParams) =>
  getBlob(Api.GET_DATA_BY_SCOPE_EXPORT, params);

// 按范围分布-按排放类别导出excel
export const scopeClassExport = (params: ScopeClassExportParams) =>
  getBlob(Api.GET_DATA_BY_CLASS_EXPORT, params);

// 按范围分布-导出温室气体类型分布excel
export const scopeSourceExport = (params: ScopeSourceExportParams) =>
  getBlob(Api.GET_DATA_BY_SOURCE_EXPORT, params);

// 按时间分布
export const getPeriodList = (params: GetPeriodListParams): Promise<GetPeriodListResult[]> =>
  get(Api.GET_DATA_PERIOD, params);

// 按时间分布-月度碳排放趋势
export const getMonthPeriodList = (
  params: GetMonthPeriodListParams
): Promise<GetMonthPeriodListResult[]> => get(Api.GET_DATA_PERIOD_MONTH, params);

// 按按时间分布-导出碳排放数据对比
export const periodExport = (params: PeriodExportParams) =>
  getBlob(Api.GET_DATA_PERIOD_EXPORT, params);

// 按时间分布-月度碳排放趋势-导出排放强度excel
export const periodIntensityExport = (params: PeriodIntensityExportParams) =>
  getBlob(Api.GET_DATA_PERIOD_INTENSITY_EXPORT, params);

// 盘查-图形化趋势-近12月碳排放及强度趋势分析 - 王佩宇
export const queryAnalysis = (params: queryAnalysisParams): Promise<queryAnalysisRes> =>
  get(Api.GET_MONTH_QUERYANALYSIS, params);
// 盘查-图形化趋势-按年碳排放及强度趋势分析 - 王佩宇
export const queryAnalysisYear = (params: queryAnalysisYearParams): Promise<queryAnalysisRes> =>
  get(Api.GET_YEAR_QUERYANALYSIS, params);
// 盘查-碳排放分布分析-饼图
export const queryOrgAnalysis = (
  params: queryOrgAnalysisParams
): Promise<queryOrgAnalysisPieRes[]> => get(Api.GET_PIE_QUERYORGANALYSIS, params);
// 盘查-碳排放分布分析-按排放源-柱图
export const queryOrgByGhgSourceAnalysis = (params: queryOrgAnalysisParams) =>
  get(Api.GET_BAR_QUERYORGBYGHGSOURCEANALYSIS, params);
// 盘查-碳排放分布分析-桑基图
export const queryOrgByMaterialItemAnalysis = (
  params: queryOrgAnalysisParams
): Promise<queryOrgAnalysisSankeyRes> => get(Api.GET_SANKEY_QUERYORGBYMATERIALITEMANALYSIS, params);
// 下载各标准的报表
export const getStaticReport = (params: queryAnalysisParams) =>
  getBlob(Api.GET_STATISTICSREPORT_EXPORT, params);
// 盘查-图形趋势分析-标头
export const queryAnalysisHeader = (params: queryAnalysisParams): Promise<analysisTopType> =>
  get(Api.GET_ANALYSIS_HEADER, params);

/**
 * 可视化查询任务信息
 * @param orgCode
 * @param inventoryYear
 * @returns boundaryType: SELF_FILL-工厂叶子；CHILD_FILL-父级节点
 */
export const getTrendQueryTask = (
  orgCode: string,
  inventoryYear: string
): Promise<{ boundaryType: 'SELF_FILL' | 'CHILD_FILL' }> =>
  get(Api.TREND_QUERY_TASK, { orgCode, inventoryYear });
